// Package middleware
// @File: requestContext.go
// @Description: 向RequestContext中增加与该 HTTP 请求关联的上下文
// @Author: YaoRuiQi
// @Date: 2025/8/27 17:53

package middleware

import (
	"GinStandardTemplate/internal/pkg/contextUtils"

	"github.com/gin-gonic/gin"
)

func RequestContextMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		ctx, _ := contextUtils.FromContext(c.Request.Context())
		c.Request = c.Request.WithContext(contextUtils.NewRequestContext(
			c.Request.Context(), &contextUtils.RequestContext{
				RequestID: ctx.RequestID,
				Localizer: ctx.Localizer,
				UserData:  ctx.UserData,
				Logger:    ctx.Logger,
				Ctx:       c.Request.Context(),
			},
		))

		c.Next()
	}
}
